const mongoose = require("mongoose");

async function connectDB() {
    const uri = process.env.MONGODB_URI;
    if (!uri) {
        throw new Error("MONGODB_URI 未配置");
    }
    mongoose.set("strictQuery", true); // 避免无效查询警告
    await mongoose.connect(uri, {
        autoIndex: true, // 开发环境便于调试，生产可关
    });
    console.log("✅ MongoDB 已连接:", uri);
}

module.exports = connectDB;
